<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Goods_Order extends Model
{
    // 订单表
    protected $table = "goods_order";
    public $timestamps = false;
    protected $guarded = ['id'];

    public function goods()
    {
        return $this->belongsTo('App\Goods', 'item_id');
    }

    public function seller()
    {
        return $this->belongsTo('App\Craftsman', 'seller_id');
    }

    public function buyer()
    {
        return $this->belongsTo('App\User', 'buyer_id');
    }

    protected static function booted()
    {
        static::addGlobalScope('info', function (Builder $builder) {
            $builder->with(['goods:id,title,image_src,price','seller:id,shop_name','buyer:id,nickname']);
        });
    }
}
